//package com.inspur.edp.bef.dtgenerator.core.rtgen.managergen.method;
//
//import com.inspur.edp.caf.generator.baseInfo.ParameterInfo;
//import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
//import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
//import com.inspur.edp.cef.api.attr.UQConstraintInfoAttribute;
//import com.inspur.edp.cef.entity.UQConstraintConfig;
//import com.inspur.edp.cef.entity.config.MgrConfig;
//import com.inspur.edp.cef.gencommon.ReflectionUtils;
//import com.inspur.edp.cef.gencommon.config.CefConfigUtils;
//import com.inspur.edp.cef.generator.coreGenerator.base.mgrGenerator.ManagerGeneratorContext;
//import com.inspur.edp.cef.rtgenerator.managergen.ManagerGeneratorContext;
//import com.inspur.edp.cef.spi.manager.IUQConstraintInfo;
//import com.inspur.edp.lcm.metadata.api.entity.MetadataHeader;
//import lombok.var;
//import org.eclipse.jdt.core.dom.*;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.Map;
//
//public class GetConstraintInfoGenerator extends ClassMethodGenerator
//{
//	private ManagerGeneratorContext parentContext;
//
//	public GetConstraintInfoGenerator(ManagerGeneratorContext parentContext)
//	{
//		this.parentContext = parentContext;
//
//	}
//
//	@Override
//	protected String getMethodName()
//	{
//		return "getConstraintInfo";
//	}
//
//	@Override
//	protected TypeInfo getReturnType()
//	{
//		addImport(HashMap.class.getName());
//		TypeInfo typeInfo = new TypeInfo(HashMap.class);
//		typeInfo.setIsParameterizedType(true);
//
//		typeInfo.getArguments().add(new TypeInfo(String.class));
//
//		TypeInfo argType2 = new TypeInfo(ArrayList.class );
//		argType2.setIsParameterizedType(true);
//
//		TypeInfo argTypeUQ = new TypeInfo(UQConstraintConfig.class);
//		argType2.getArguments().add(argTypeUQ);
//		typeInfo.getArguments().add(argType2);
//		return typeInfo;
//	}
//
//	@Override
//	protected boolean getIsOverride() {
//		return true;
//	}
//
//	@Override
//	protected ArrayList<Modifier.ModifierKeyword> getAccessModifiers() {
//		return new ArrayList<>(Arrays.asList(new Modifier.ModifierKeyword[]{Modifier.ModifierKeyword.PUBLIC_KEYWORD}));
//	}
//
//	@Override
//	protected ArrayList<ParameterInfo> getParameterCollection() {
//		return null;
//	}
//
//	private java.util.HashMap<String, java.util.ArrayList<UQConstraintConfig>> getContent()
//	{
//		java.util.HashMap<String, java.util.ArrayList<UQConstraintConfig>> result = null;
//		MgrConfig mgrConfig = parentContext.getProjContext().getCefConfig().getMgrConfig();
//		ArrayList<String> jarList = new ArrayList<String>(){
//			{
//				add(parentContext.getProjContext().getCompileContext().getApiJarFileName());
//				add(parentContext.getProjContext().getCompileContext().getCoreJarFileName());
//			}
//		};
//		Class type= CefConfigUtils.getType(jarList,mgrConfig.getImpAssembly(),mgrConfig.getImpClass()) ;
//		UQConstraintInfoAttribute attr = (UQConstraintInfoAttribute) ReflectionUtils.getAnnotation(type,UQConstraintInfoAttribute.class);
//		if (attr != null)
//		{
//			Object tempVar =ReflectionUtils.createInstance(attr.value());
//			IUQConstraintInfo assembler = (IUQConstraintInfo)((tempVar instanceof IUQConstraintInfo) ? tempVar : null);
//			result = assembler.getUQConstraintInfo();
//		}
//		if (result == null)
//		{
//			result = new java.util.HashMap<String, java.util.ArrayList<UQConstraintConfig>>();
//		}
//		return result;
//
//	}
//
//	@Override
//	protected Block buildMethodBody() {
//		addImport(UQConstraintConfig.class.getName());
//		Block block = ast.newBlock();
//		addNewHashMapExpression(block);
//		addSetNodesExpressions(block);
//		addReturnExpression(block);
//		return block;
//	}
//
//	private void addNewHashMapExpression(Block block) {
//		VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//		variableDeclarationFragment.setName(ast.newSimpleName("dict"));
//		setHashSetVariableInitializer(variableDeclarationFragment);
//		VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//		setHashSetType(variableDeclarationStatement);
//		block.statements().add(variableDeclarationStatement);
//
//	}
//
//
//	private void setHashSetVariableInitializer(VariableDeclarationFragment variableDeclarationFragment) {
//		ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//		ParameterizedType type =ast.newParameterizedType(ast.newSimpleType(ast.newName(HashMap.class.getTypeName())));
//		classInstanceCreation.setType(type);
//		variableDeclarationFragment.setInitializer(classInstanceCreation);
//	}
//
//	private void setHashSetType(VariableDeclarationStatement variableDeclarationStatement) {
//		ParameterizedType type =ast.newParameterizedType(ast.newSimpleType(ast.newName(HashMap.class.getTypeName())));
//		type.typeArguments().add(ast.newSimpleType(ast.newSimpleName("String")));
//
//		ParameterizedType listType =ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName())));
//		listType.typeArguments().add(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//
//		type.typeArguments().add(listType);
//		variableDeclarationStatement.setType(type);
//	}
//
//	private void addSetNodesExpressions(Block block) {
//		HashMap<String, ArrayList<UQConstraintConfig>> contents =getContent();
//		if(contents ==null||contents.size()==0) {
//			return;
//		}
//		for (Map.Entry<String,ArrayList<UQConstraintConfig>> content:contents.entrySet())
//		{
//			addSetNodeExpression(block,content);
//		}
//	}
//
//	//    ArrayList<UQConstraintConfig> list =new ArrayList<>();
////    for (UQConstraintConfig config1:content.getValue())
////    {
////      UQConstraintConfig config=new UQConstraintConfig();
////      ArrayList<String> fields =new ArrayList<>();
////      fields.add("ff1");
////      config.setConstraintFields(fields);
////      config.setMessage("ddd");
////      list.add(config);
////    }
////    dic.put("sdaf",list);
//	private void addSetNodeExpression(Block block, Map.Entry<String, ArrayList<UQConstraintConfig>> content) {
//		Block block1=ast.newBlock();
//		addSetNodeNewConfigList(block1);
//		for (UQConstraintConfig config:content.getValue()) {
//			addSetConfigExpression(content.getKey(), config, block1);
//		}
//        setAddListToDict(content,block1);
//		block.statements().add(block1);
//	}
//
//    private void setAddListToDict(Map.Entry<String, ArrayList<UQConstraintConfig>> content, Block block1) {
//        MethodInvocation methodInvocation=ast.newMethodInvocation();
//        methodInvocation.setName(ast.newSimpleName("put"));
//        methodInvocation.setExpression(ast.newSimpleName("dict"));
//        StringLiteral stringLiteral=ast.newStringLiteral();
//        stringLiteral.setLiteralValue(content.getKey());
//        methodInvocation.arguments().add(stringLiteral);
//        methodInvocation.arguments().add(ast.newSimpleName("list"));
//        block1.statements().add(ast.newExpressionStatement(methodInvocation));
//    }
//
//	private void addSetConfigExpression(String nodeCode, UQConstraintConfig config, Block block1) {
//		Block block2= ast.newBlock();
//		addNewConfig(block2,config);
//		addSetNodeConfigFields(block2,config);
//		addSetNodeConfigMessage(nodeCode, block2,config);
//		addAddConfigToList(block2);
//		block1.statements().add(block2);
//	}
//
//	private void addNewConfig(Block block1, UQConstraintConfig config) {
//		VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//		variableDeclarationFragment.setName(ast.newSimpleName("config"));
//		ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//		classInstanceCreation.setType(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//		variableDeclarationFragment.setInitializer(classInstanceCreation);
//		VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//		variableDeclarationStatement.setType(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//		block1.statements().add(variableDeclarationStatement);
//	}
//
//	private void addAddConfigToList(Block block1) {
////list.add(config);
//		MethodInvocation methodInvocation=ast.newMethodInvocation();
//		methodInvocation.setName(ast.newSimpleName("add"));
//		methodInvocation.setExpression(ast.newSimpleName("list"));
//		methodInvocation.arguments().add(ast.newSimpleName("config"));
//		block1.statements().add(ast.newExpressionStatement(methodInvocation));
//	}
//
//	private void addSetNodeNewConfigList(Block block1) {
//		VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//		variableDeclarationFragment.setName(ast.newSimpleName("list"));
//		ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//		classInstanceCreation.setType(ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName()))));
//		variableDeclarationFragment.setInitializer(classInstanceCreation);
//
//		VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//		ParameterizedType parameterizedType=ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName())));
//		parameterizedType.typeArguments().add(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//		variableDeclarationStatement.setType(parameterizedType);
//		block1.statements().add(variableDeclarationStatement);
//	}
//
//	private void addSetNodeConfigFields(Block block1, UQConstraintConfig config) {
//		addNewFieldList(block1);
//		setFieldItems(block1,config);
//		addSetFields(block1,config);
//	}
//
//	private void setFieldItems(Block block1, UQConstraintConfig config) {
//		for(String field:config.getConstraintFields())
//		{
//			MethodInvocation methodInvocation=ast.newMethodInvocation();
//			methodInvocation.setName(ast.newSimpleName("add"));
//			methodInvocation.setExpression(ast.newSimpleName("fields"));
//			StringLiteral stringLiteral=ast.newStringLiteral();
//			stringLiteral.setLiteralValue(field);
//			methodInvocation.arguments().add(stringLiteral);
//			block1.statements().add(ast.newExpressionStatement(methodInvocation));
//		}
//	}
//
//	private void addSetFields(Block block1, UQConstraintConfig config) {
////    config.setConstraintFields(fields);
//		MethodInvocation methodInvocation=ast.newMethodInvocation();
//		methodInvocation.setName(ast.newSimpleName("setConstraintFields"));
//		methodInvocation.setExpression(ast.newSimpleName("config"));
//		methodInvocation.arguments().add(ast.newSimpleName("fields"));
//		block1.statements().add(ast.newExpressionStatement(methodInvocation));
//	}
//
//	private void addNewFieldList(Block block1) {
//		VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//		variableDeclarationFragment.setName(ast.newSimpleName("fields"));
//		ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//		classInstanceCreation.setType(ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName()))));
//		variableDeclarationFragment.setInitializer(classInstanceCreation);
//		VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//		ParameterizedType parameterizedType=ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName())));
//		parameterizedType.typeArguments().add(ast.newSimpleType(ast.newSimpleName("String")));
//		variableDeclarationStatement.setType(parameterizedType);
//		block1.statements().add(variableDeclarationStatement);
//	}
//
//	/**
//	 * config.setMessage(getModelInfo().getCustomResource("nodeCode").getUniqueConstraintMessage("CodeValid"));
//	 * @param block1
//	 * @param config
//	 */
//	private void addSetNodeConfigMessage(String nodeCode, Block block1, UQConstraintConfig config) {
////config.setMessage("");
//		MethodInvocation methodInvocation=ast.newMethodInvocation();
//		methodInvocation.setName(ast.newSimpleName("setMessage"));
//		methodInvocation.setExpression(ast.newSimpleName("config"));
//
//		//getModelInfo()部分
//		//getModelInfo().getCustomResource(getModelInfo().getRootNodeCode())
//		MethodInvocation getModelMethod = ast.newMethodInvocation();
//		getModelMethod.setName(ast.newSimpleName("getModelInfo"));
//		MethodInvocation method = ast.newMethodInvocation();
//		method.setExpression(getModelMethod);
//		method.setName(ast.newSimpleName("getCustomResource"));
//		StringLiteral nodeCodeLiteral=ast.newStringLiteral();
//		nodeCodeLiteral.setLiteralValue(nodeCode);
//		method.arguments().add(nodeCodeLiteral);
//
//		MethodInvocation method3 = ast.newMethodInvocation();
//		method3.setExpression(method);
//		method3.setName(ast.newSimpleName("getUniqueConstraintMessage"));
//		StringLiteral stringLiteral=ast.newStringLiteral();
//		stringLiteral.setLiteralValue(config.getUQConstraintCode());
//		method3.arguments().add(stringLiteral);
//
//		methodInvocation.arguments().add(method3);
//		block1.statements().add(ast.newExpressionStatement(methodInvocation));
//	}
//
//	private void addReturnExpression(Block block) {
//		ReturnStatement returnStatement=ast.newReturnStatement();
//		returnStatement.setExpression(ast.newSimpleName("dict"));
//		block.statements().add(returnStatement);
//	}
//}